<template>
  <div>
    <div class="table-container" style="height: 310px;">
      <div class="TableTitle">
        <div class="priority">优先级</div>
        <div class="kind">种类</div>
        <div class="explain">说明</div>
        <div class="isStartUsing">启用</div>
      </div>
      <div class="TableContent" @click="onClickDiv(index)" :class="index === nowIndex ? 'active' : ''"
        v-for="(item, index) in tableData" :key="index">
        <span style="
            font-size: 12px;
            display: inline-block;
            width: 0.937559rem;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border-right: 0.018751rem solid #cbced3;
            vertical-align:bottom;
          ">{{ item.priorityName ? index + 1 : '' }}</span>
        <span style="
            font-size: 12px;
            display: inline-block;
            width: 2.250141rem;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border-right: 0.018751rem solid #cbced3;
            vertical-align:bottom;
          ">{{ item.priorityName }}</span>
        <span style="
            font-size: 12px;
            display: inline-block;
            width: 4.687793rem;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border-right: 0.018751rem solid #cbced3;
            vertical-align:bottom;
          ">{{ item.explains }}</span>

        <!-- 启用状态 0-启用，1-停用 -->
        <el-checkbox v-if="item.priorityName"
          style="width: 1.875117rem; height: 40px; line-height: 40px; text-align: center" true-label="0" false-label="1"
          v-model="item.status"></el-checkbox>
      </div>
    </div>
    <div class="move">
      <el-button type="primary" @click="upMove" icon="el-icon-top" size="mini">上移</el-button>
      <el-button type="primary" @click="downMove" icon="el-icon-bottom" size="mini">下移</el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: ['tableData'],
  data() {
    return {
      nowIndex: -1,
    }
  },
  watch: {
    tableData(newV, oldV) {
      if (JSON.stringify(newV) != JSON.stringify(oldV)) {
        this.nowIndex = -1
      }
    },
  },
  methods: {
    onClickDiv(i) {
      this.tableData.forEach((item, index) => {
        if (index == i && item.priorityName) {
          this.nowIndex = index
        }
      })
    },
    upMove() {
      if (this.nowIndex > 0) {
        let upDate = this.tableData[this.nowIndex - 1]
        this.tableData.splice(this.nowIndex - 1, 1)
        this.tableData.splice(this.nowIndex, 0, upDate)
        this.nowIndex = this.nowIndex - 1
      }
      this.handleTableData()
    },
    downMove() {
      if (this.nowIndex + 1 === this.tableData.length) {
        return
      } else {
        let upDate = this.tableData[this.nowIndex + 1]
        this.tableData.splice(this.nowIndex + 1, 1)
        this.tableData.splice(this.nowIndex, 0, upDate)
        this.nowIndex = this.nowIndex + 1
      }
      this.handleTableData()
    },
    handleTableData() {
      for (let index = 0; index < this.tableData.length; index++) {
        let element = this.tableData[index];
        element.idx = index
      }
    },
  },
}
</script>

<style scoped lang="scss">
.active {
  background-color: rgb(227, 246, 255);
}

.table-container {
  width: 9.806863rem;
  border: 0.018751rem solid #cbced3;
  margin-top: 30px;
}

.TableTitle {
  display: flex;
  width: 9.806863rem;
  height: 30px;
  background-color: rgb(238, 238, 238);
  font-size: 12px;
  color: #666;

  .priority {
    width: 0.937559rem;
    text-align: center;
    line-height: 30px;
    border-right: 0.018751rem solid #cbced3;
  }

  .kind {
    width: 2.250141rem;
    line-height: 30px;
    text-align: center;
    border-right: 0.018751rem solid #cbced3;
  }

  .explain {
    width: 4.687793rem;
    text-align: center;
    line-height: 30px;
    border-right: 0.018751rem solid #cbced3;
  }

  .isStartUsing {
    width: 1.875117rem;
    text-align: center;
    line-height: 30px;
  }
}

.TableContent {
  color: #666;
}

.move {
  position: absolute;
  left: 10.87568rem;
  top: 410px;
  width: 1.875117rem;

  //   display: flex;
  //   flex-direction: column;
  .el-button {
    display: block;
    width: 60px;
    height: 30px;
    color: #1890fc;
    background: #e6f7ff;
    border: 0.018751rem solid #91d5fe;
    text-align: center;

    &:last-child {
      margin-left: 0;
      margin-top: 14px;
    }

    ::v-deep .el-icon-bottom {
      margin-left: -0.075005rem;
    }

    ::v-deep .el-icon-top {
      margin-left: -0.075005rem;
    }

    ::v-deep span {
      margin: 0;
    }
  }
}
</style>